package com.apes.framework.jpa.logger;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.outbox.annotation.OutBoxExclude;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;
import java.util.Map;

//import com.apes.scm.rbac.model.User;

/**
 * 功能：业务操作日志
 *
 * @author xul
 * @create 2018-07-26 10:09
 */
@OutBoxExclude
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ApesLogger.CONST_TABLE_NAME, indexes = {@Index(name = "ir_logger_business_key", columnList = "business_type, business_key")})
public class ApesLogger extends BaseModel {
    public static final String CONST_TABLE_NAME = "ir_logger";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "业务操作日志")
    private long id;

    @Column(name = "business_type", length = 125)
    private String businessType; //单据类型

    @Column(name = "business_key", length = 125)
    private String businessKey; //单据ID

//    @ManyToOne(fetch = FetchType.LAZY)
//    @JoinColumn(name = "operator_id", referencedColumnName = "id")
//    private User operator;  //操作人

    @Column(name = "operator_id")
    private Integer operator_id; //操作人(User.id)

    @Column(name = "operator_name")
    private String operatorName; //操作人(User.name)

    @Transient
    private Map operator;

    @Column(name = "operate", length = 125)
    private String operate; //操作

    @Column(name = "remark", length = 2000)
    private String remark; // 备注

    @Column(name = "oa_flag")
    private boolean oaFlag = false; //OA操作标记

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "business_date")
    private Date businessDate; //业务发生时间

    @Column(name = "work_post_name", length = 250)
    private String workPostName;

    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "auditing", columnDefinition = "CLOB")
    @Comment("审计内容")
    private String audit;
}
